import React, { ReactElement } from 'react'
import ReactDOM from 'react-dom'
import createBrowserHistory from 'history/createBrowserHistory'
import appRouter from './app-router'
import { AppContainer } from 'react-hot-loader'
import store from '@stores/index'
import api from 'api'

window.debug = __DEBUG__ ? console.log.bind(console) : () => { }

api(store.dispatch)

const history = createBrowserHistory()

const root = document.getElementById('root')
const render = (Component: ReactElement) => {
  ReactDOM.render(<AppContainer>{Component}</AppContainer>, root)
}

render(appRouter(history))
if (module.hot) {
  module.hot.accept('./app-router', () => {
    render(appRouter(history))
  })
}
